<?php

require_once("inc.member.php");

if($get_s["select_lan"]) $_SESSION['lan'] = $get_s["select_lan"];

$this_title="$vars[title] &raquo; ".__("Member's Home");

$page_title=__("Member's Home");

$content_title=__("Member's Home");





$r_yesno_d=array("y"=>__("Yes"), "n"=>__("No"));



$td_width=190;



if(ntime()<mktime(0,0,0,3,20,2010)){

$new_server_news = "<h3>Welcome back! We have migrated to the new, more powerful server to better serve our customers needs. As with this, the following operations will be carried out in the coming few days:<br /><br />

<ol>

	<li>The pairing bonus will be re-calculated, starting from 6-March-2010 until 14-March-2010.</li>

	<li>The bonus for the previous calculated pairing bonus (6 March onwards) will be reversed from your e-Wallet account (if any)</li>

	<li>The maintenance deducted from the previous pairing bonus, however will not be reversed (6 March to 14 March), but re-calculation of the pairing bonus will not deduct the bonus for maintenance until 14 March, however

	maintenance will continue on 15 March onwards</li>

	<li>After re-calculations for 6 March to 14 March are completed, the system will continue with normal calculation.</li>

</ol>

</h3>";

}



//javascript

ob_start();
?>

<script type='text/javascript' src='<?php echo JS_URL."/get_file_gzip.php?file=".urlencode("jquery.js"); ?>'></script>

<script type='text/javascript'>
jQuery(document).ready(function(j){

	j('a[@name^=sinfo_]').click(function(){

		var ename = j(this).attr('name');

		var etype = j(this).text();

		if(etype == '+'){

			j(this).html('-');

			j('div#'+ename).slideDown();

		}else{

			j(this).html('+');

			j('div#'+ename).slideUp();

		}

		return false;

	});

});

</script>

<?php

$jvscript = ob_get_clean();



$this_year = ndate('Y');

$this_month = ndate('n');

$this_month_starttime = mktime(0,0,0,ndate('n'),1,ndate('Y'));

$this_month_endtime = mktime(23,59,59,ndate('n')+1,0,ndate('Y'));

$this_month_start = date("Y-m-d H:i:s", $this_month_starttime);

$this_month_end = date("Y-m-d H:i:s", $this_month_endtime);

$last_month_time = mktime(0,0,0,$this_month-1,1,$this_year);

$last_year = date('Y', $last_month_time);

$last_month = date('n', $last_month_time);

$next_month_time = mktime(0,0,0,$this_month+1,1,$this_year);

$next_year = date('Y', $next_month_time);

$next_month = date('n', $next_month_time);

$last_month_starttime = mktime(0,0,0,$this_month-1,1,ndate('Y'));

$last_month_endtime = mktime(23,59,59,$this_month,0,ndate('Y'));

$last_month_start = date("Y-m-d H:i:s", $last_month_starttime);

$last_month_end = date("Y-m-d H:i:s", $last_month_endtime);

$this_month_maintain = @mysql_result(mysql_query("select sum(amount) from $db->member_maintain where uid='$uid' and year='$this_year' and month='$this_month'"), 0);

$last_month_maintain = @mysql_result(mysql_query("select sum(amount) from $db->member_maintain where uid='$uid' and year='$last_year' and month='$last_month'"), 0);

$next_month_maintain = @mysql_result(mysql_query("select sum(amount) from $db->member_maintain where uid='$uid' and year='$next_year' and month='$next_month'"), 0);

$this_month_maintain_sales = calc_personal_sales($uid, $this_month_start, $this_month_end);

$last_month_maintain_sales = calc_personal_sales($uid, $last_month_start, $last_month_end);
$ymd = ndate('Ymd');
$ym = ndate('Ym');
$today_amount = @mysql_result(mysql_query("select sum(a.total_bv) from $db->purchase a inner join $db->users b on b.id=a.uid and b.ref='$uid' where a.status='confirmed' and date_format(a.cdate,'%Y%m%d')='".$ymd."'"), 0);
$total_amount = @mysql_result(mysql_query("select sum(a.total_bv) from $db->purchase a inner join $db->users b on b.id=a.uid and b.ref='$uid' where a.status='confirmed'"), 0);
$today_dist = @mysql_result(mysql_query("select count(*) from $db->users where ref='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$total_dist = @mysql_result(mysql_query("select count(*) from $db->users where ref='$uid'"), 0);
$flash_date = @mysql_result(mysql_query("select flash_date from $db->users where ref='$uid'"), 0);
$today_sponsor = @mysql_result(mysql_query("select s from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$today_pairing = @mysql_result(mysql_query("select p from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$today_leadership = @mysql_result(mysql_query("select l from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$today_bonus = @mysql_result(mysql_query("select s+p+l from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$month_bonus = @mysql_result(mysql_query("select sum(s+p+l) from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m')='".$ym."'"), 0);
$total_bonus = @mysql_result(mysql_query("select sum(s+p+l) from $db->member_comm_sum where uid='$uid' group by uid"), 0);
$left_group = @mysql_result(mysql_query("select lcf from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);
$right_group = @mysql_result(mysql_query("select rcf from $db->member_comm_sum where uid='$uid' and date_format(cdate,'%Y%m%d')='".$ymd."'"), 0);

if($uid==229){
	$total_amount += 24000;
	$right_group += 8000;
} 

$point=
"                
		        <div class='widget'>
			        <div class='widget-header'>
			            <h3><span id='lblSalesInformation'>".__("Your Wallet")."</span></h3>
			        </div>
			        <div class='widget-content'>
			            <table class='table table-striped table-highlight'>
<tr>

		<td width='$td_width'>".replace_tag(__("<%title%> Balance"), array("<%title%>"=>__($vars["ewallet_title"]))).__(":")."</td>

		<td>".number_format($r_user["ewallet"], 0)."</td>

	</tr>

	<tr>

		<td width='$td_width'>".replace_tag(__("<%title%> Balance"), array("<%title%>"=>__($vars["eswallet_title"]))).__(":")."</td>

		<td>".number_format($r_user["eswallet"], 0)."</td>

	</tr>

	<tr>

		<td width='$td_width'>".replace_tag(__("<%title%> Balance"), array("<%title%>"=>__($vars["swallet_title"]))).__(":")."</td>

		<td>".number_format($r_user["swallet"], 0)."</td>

	</tr>

	<tr>

		<td width='$td_width'>".replace_tag(__("<%title%> Balance"), array("<%title%>"=>__($vars["mwallet_title"]))).__(":")."</td>

		<td>".number_format($r_user["mwallet"], 0)."</td>

	</tr>

	<tr style='display:none'>

		<td width='$td_width'>".replace_tag(__("<%title%> Wallet Balance"), array("<%title%>"=>__($vars["cwallet_title"]))).__(":")."</td>

		<td>".number_format($r_user["cwallet"], 2)."</td>

	</tr>

                        </table>
			        </div>
                </div>	
";

$ttl_record=@mysql_num_rows($r=mysql_query("SELECT * FROM gg_news WHERE f_status='active' ORDER BY f_date DESC"));

$annoucement=
"                
		        <div class='widget'>
			        <div class='widget-header'>
			            <h3><span id='lblSalesInformation'>".__("Annoucement")."</span></h3>
			        </div>
			        <div class='widget-content'>
			            <table class='table table-striped table-highlight'>";

for($i=0; $i<$ttl_record; $i++){		            
	$news=mysql_fetch_assoc($r);
	
$annoucement.=
"			            
	<tr>

		<td width='80px'>".$news['f_date']."</td>

		<td>".$news['f_content']."</td>

	</tr>";
}

$annoucement.="
                        </table>
			        </div>
                </div>	
";

$link = '<button onclick="location.href=\'group_sales_history.php\'">'.__('View').'</button>';

$earning = 

'<div class="widget">
			        <div class="widget-header">
				        <h3>
					        <span id="lblEARNINGS">'.__('Exchange Rate for 100 e-Register').'</span>
				        </h3>
			        </div>
			        <div class="widget-content">
						<table class="table table-striped table-highlight">		
						    <tr>
						        <td><strong><span id="lblCurrency_lbl">'.__('CNY').'</span></strong></td>
						        <td class="actions"><span id="lblCurrency"><b>6.80</b></span></td>
						        <td class="actions"><span id="lblCurrency"><b>6.20</b></span></td>
						    </tr>							
						    <tr>
						        <td><strong><span id="lblCurrency_lbl">'.__('HKD').'</span></strong></td>
						        <td class="actions"><span id="lblCurrency"><b>8.20</b></span></td>
						        <td class="actions"><span id="lblCurrency"><b>7.40</b></span></td>
						    </tr>						
						    <tr>
						        <td><strong><span id="lblCurrency_lbl">'.__('MYR').'</span></strong></td>
						        <td class="actions"><span id="lblCurrency"><b>3.80</b></span></td>
						        <td class="actions"><span id="lblCurrency"><b>3.20</b></span></td>
						    </tr>
						</table>                     
			        </div>
			        <br>
			        <div class="widget-header" style="display:none">
				        <h3>
					        <span id="lblEARNINGS">'.__('Profit Earnings').'</span>
				        </h3>
			        </div>
			        <div class="widget-content" style="display:none">
						<table class="table table-striped table-highlight">
							<tr>
						    	<td><strong><span id="lblTodaySponsorBonus_lbl">'.__('Today Sponsor Bonus').'</span></strong></td>
						        <td class="actions"><span id="lblTodaySponsorBonus"><b>'.$vars["currency"].number_format($today_sponsor,2).'</b></span></td>
						    </tr>
						    <tr>
						        <td><strong><span id="lblTodayPairing_lbl">'.__('Today Pairing Bonus').'</span></strong></td>
						        <td class="actions"><span id="lblTodayPairing"><b>'.$vars["currency"].number_format($today_pairing,2).'</b></span></td>
						    </tr>
						    <tr>
						        <td><strong><span id="lblTodayMatching_lbl">'.__('Today Leadership Bonus').'</span></strong></td>
						        <td class="actions"><span id="lblTodayMatching"><b>'.$vars["currency"].number_format($today_leadership,2).'</b></span></td>
						    </tr>
							<tr>
								<td><strong><span id="lblToday">'.__('Today earnings').'</span></strong></td>
								<td class="actions"><span id="lblTodayBonus"><b>'.$vars["currency"].number_format($today_bonus,2).'</b></span></td>
							</tr>
							<tr>
								<td><strong><span id="lblThisMth">'.__('This month earnings').'</span></strong></td>
								<td class="actions"><span id="lblThisMthBonus"><b>'.$vars["currency"].number_format($month_bonus,2).'</b></span></td>
							</tr>
							<tr>
								<td><strong><span id="lblTotal">'.__('Total earnings').'</span></strong></td>
								<td class="actions"><span id="lblTotalBonus"><b>'.$vars["currency"].number_format($total_bonus,2).'</b></span></td>
							</tr>
						</table>                     
			        </div>
			        <br>
			        <div class="widget-header" style="display:none">
				        <h3>
					        <span id="lblEARNINGS">'.__('Sales Information').'</span>
				        </h3>
			        </div>
			        <div class="widget-content" style="display:none">
						<table class="table table-striped table-highlight">							
						    <tr>
						        <td><strong><span id="lblFlash_lbl">'.__('Flash Date').'</span></strong></td>
						        <td class="actions"><span id="lblFlash"><b>'.$flash_date.'</b></span></td>
						    </tr>
							<tr>
						    	<td><strong><span id="lblLeftSales_lbl">'.__('Left Group Sales').'</span></strong></td>
						        <td class="actions"><span id="lblLeftSales"><b>'.number_format($left_group,0).'</b></span>&nbsp;&nbsp;&nbsp;'.$link.'</td>
						    </tr>
						    <tr>
						        <td><strong><span id="lblRightSales_lbl">'.__('Right Group Sales').'</span></strong></td>
						        <td class="actions"><span id="lblRightSales"><b>'.number_format($right_group,0).'</b></span>&nbsp;&nbsp;&nbsp;'.$link.'</td>
						    </tr>
						    <tr>
						        <td><strong><span id="lblTodaySales_lbl">'.__('Today Sales').'</span></strong></td>
						        <td class="actions"><span id="lblTodaySales"><b>'.$vars["currency"].number_format($today_amount,2).'</b></span></td>
						    </tr>
							<tr>
								<td><strong><span id="lblTotalSales_lbl">'.__('Total Sales').'</span></strong></td>
								<td class="actions"><span id="lblTotalSales"><b>'.$vars["currency"].number_format($total_amount,2).'</b></span></td>
							</tr>
							<tr>
								<td><strong><span id="lblTodayDist_lbl">'.__('Today Distributor').'</span></strong></td>
								<td class="actions"><span id="lblTodayDist"><b>'.number_format($today_dist,0).'</b></span></td>
							</tr>
							<tr>
								<td><strong><span id="lblTotalDist_lbl">'.__('Total Distributor').'</span></strong></td>
								<td class="actions"><span id="lblTotalDist"><b>'.number_format($total_dist,0).'</b></span></td>
							</tr>
						</table>                     
			        </div>
		        </div>	        		        
            </div>';

$content=$new_server_news.'<div class="row"><div class="span8">
'.$acc.$point.$annoucement.'</div><div class="span4">'.$earning.'</div></div>';



print format_member_page($content, $this_title, $content_title, $jvscript);

?>